/*
 * ProcAssignInstrucDescription.java
 * 
 * last update: 24.01.2010 by Olaru Victor
 * 
 * author:	Victor(victor.olaru@gmail.com)
 * 
 * Obs:
 */

package engine;

/**
 * Implements the description of a procedural assignement
 * <PRE><CODE>
 * ex:
 *     #1 a #2 = b ;  //blocking
 *   or:
 *     b <= a;     //non-blocking
 * </CODE><PRE>
 */
@SuppressWarnings("serial")
class ProcAssignInstrucDescription extends InstructionDescription{

	ExpressionDescription rValue;
	AssignableSelection lValue;
	int delayInside;
	boolean blocking;

	public ProcAssignInstrucDescription(int delayBefore, int line,
			NameSpaceDescription nsd,
			AssignableSelection lValue,
			ExpressionDescription rValue,
			int delayinside, boolean blocking){
		super(delayBefore, line, nsd);
		this.rValue = rValue;
		this.lValue = lValue;
		delayInside = delayinside;
		this.blocking = blocking;
	}

	DefaultInstruction instantiate(NameSpace ns)throws ParseException{

		Expression rv;
		LeftValue lv;
		try{
			try{
				lv = (LeftValue)lValue.instantiate(ns);
			}catch(ClassCastException ex){
				throw new ParseException("lValue required");
			}
			if (!lv.isLeftValue()) throw new ParseException ("lValue required");
			rv = rValue.instantiate(ns);
		}catch(ParseException ex){
			xConsole.dumpStack(ex);
			throw new ParseException(super.toString() + " error:" + ex);
		}

		return new ProcAssignInstruc(ns, delayBefore, this,
				lv, rv,
				next == null ? null : next.instantiate(ns),
						delayInside, blocking);
	}

	public String toString(){
		return super.toString() + lValue + " = " + rValue;
	}
}
